package probability;

public class Combinatorics {

	public static int calcCombinations(int k, int n) {
		if (k < 0 || n < 0) {
			throw new IllegalArgumentException(
					"i can calculate combinations only for numbers >= 0");
		}

		return calcFactorial(n) / (calcFactorial(n - k) * calcFactorial(k));
	}

	public static int calcFactorial(int num) {
		if (num < 0) {
			throw new IllegalArgumentException(
					"i can calculate factorial only for number >= 0");
		}

		int result = 1;
		for (int i = 2; i <= num; i++) {
			result = result * i;
		}
		return result;
	}
}
